package com.esun.rabbit2.viewer.mainact.mylotteryact.banckbind;

import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.model.UserInfo;
import com.esun.ui.R;
import com.esun.util.log.EDebug;
import com.esun.util.webviewchromeclient.MyWebViewChromeClient;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageButton;
import android.widget.RelativeLayout;

/**
 * @ClassName: UninBindingWebAct
 * @Description: 未绑定银行卡的webview页面
 * @author: Kael gaojian@500wan.com
 * @date: 2012-7-24 上午11:09:17
 * 
 */
public class UninBindingWebAct extends Activity {
	private ImageButton btnReturn;
	private WebView wvBinding;
	private String url;
	private Handler handler;
	private RelativeLayout relativeProgress;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.uninbindingwebview_act);
		init();
		wvBinding.loadUrl(url);
	}

	private void init() {
		handler = new Handler();
		String ck = UserInfo.getUserInfo().getUserSession();
		String username = UserInfo.getUserInfo().getUserName();
		String userpassword = UserInfo.getUserInfo().getUserPwd();
		String platform = Config.NUM1;
		url = Config.ACTIVITY_UNIN_BINDING_URL + "?ck=" + ck + "&username=" + username + "&password=" + userpassword + "&platform=" + platform;
		EDebug.o("url----------------" + url);
		btnReturn = (ImageButton) findViewById(R.id.uninbindingwebview_btn_goBack);
		btnReturn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		relativeProgress = (RelativeLayout)findViewById(R.id.uninbindingwebview_act_relative_progress);
		wvBinding = (WebView) findViewById(R.id.webView_uninbindingwebview);
		WebSettings webSettings = wvBinding.getSettings();
		webSettings.setJavaScriptEnabled(true);
		webSettings.setSaveFormData(false);
		webSettings.setSavePassword(false);
		webSettings.setSupportZoom(false);
		wvBinding.setWebChromeClient(new MyWebViewChromeClient(relativeProgress));
		wvBinding.addJavascriptInterface(new JSCallBack(), "client");
	}

	class JSCallBack {

		public void bankSuccess(final String bankname, final String cardNum) {
			EDebug.o("JSCallBack", "JSCallBack被调用");
			handler.post(new JumpToBankCardBindingActRunnable(bankname, cardNum));

		}
	}

	class JumpToBankCardBindingActRunnable implements Runnable {
		private String bankname;
		private String cardNum;

		public JumpToBankCardBindingActRunnable(String bankname, String cardNum) {
			this.bankname = bankname;
			this.cardNum = cardNum;
		}
		
		@Override
		public void run() {
			Intent intent = new Intent();
			Bundle bundle = new Bundle();
			bundle.putString(Key.KEY_BANKNAME, this.bankname);
			bundle.putString(Key.KEY_CARDNUM, this.cardNum);
			// 从Webview页面进入BankCardBindingAct传1；从MyLotteryAct进入传0
			bundle.putString(Key.KEY_TAG, Config.NUM1);
			intent.putExtras(bundle);
			intent.setClass(UninBindingWebAct.this, BankCardBindingAct.class);
			UninBindingWebAct.this.startActivity(intent);
			UninBindingWebAct.this.finish();
		}

	}

}
